package cn.tedu.sync.reentrant;

public class 演示互斥 {

    public static void main(String[] args) throws InterruptedException{
        演示互斥 demo = new 演示互斥();
        Thread t = new Thread(){
            @Override
            public void run() {
                try {
                    demo.setA();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        //Thread t1 = new Thread(){
        //    @Override
        //    public void run() {
        //        try {
        //            demo.setB();
        //        } catch (InterruptedException e) {
        //            throw new RuntimeException(e);
        //        }
        //    }
        //};
        t.start();
        //t1.start();
    }


    // this
    public  synchronized void setA() throws InterruptedException {
        System.out.println("I`m  A");
        setB(); // 会不会在这里锁住
        System.out.println("I`m A结束");
        Thread.sleep(10000);
    }
    // this
    public  synchronized void setB()throws InterruptedException{
        System.out.println("I`m  b");
        Thread.sleep(10000);
    }

}
